package com.blb.controller;


import com.blb.entity.LicenseplateInformation;
import com.blb.entity.Order;
import com.blb.entity.Settlement;
import com.blb.service.ILicenseplateInformationService;
import com.blb.service.IOrderService;
import com.blb.service.ISettlementService;
import com.blb.utils.Response;
import com.blb.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaoxiong
 * @since 2020-05-27
 */
@Controller
@RequestMapping("/licenseplate-information")
public class LicenseplateInformationController {

    @Resource
    IOrderService orderService;

    @Resource
    ILicenseplateInformationService licenseplateInformationService;

    @Resource
    ISettlementService settlementService;

    @RequiresPermissions("orderlist")
    @ResponseBody
    @RequestMapping("/deliver")
    public Response getDeliver(@RequestBody(required=false) LicenseplateInformation licenseplateInformation){
        System.out.println(licenseplateInformation);
        licenseplateInformation.setId(licenseplateInformation.getOrderId());
        //把订单状态改为待生成
        Order order = new Order();
        Order byOrderID = orderService.getByOrderID(licenseplateInformation.getOrderId());
        order.setId(byOrderID.getId());
        order.setOrderStatus("已发货");
        orderService.updateById(order);

        Settlement s=new Settlement();
        s.setId(order.getOrderId());
        s.setSettlement("未结算");
        s.setCompanyId(ShiroUtils.getCompany());
        settlementService.save(s);


        licenseplateInformationService.save(licenseplateInformation);
        return Response.success();
    }

}

